<style type="text/css">
    .ladda-spinner {
        position: absolute;
        margin-top: 10px;
        margin-left: 15px;
    }
</style>
{!! Html::style(env("APP_URL").'/assets/backend/libs/ladda/ladda-themeless.min.css') !!}

<div class="ibox float-e-margins">
    <div class="ibox-content" style="display: block;">
        <div class="row">
            <div class="col-md-10">
                <div class="btn-group">
                    <a class="btn btn-primary" href="{{route('admin.shop.list.store.curd')}}">添加门店</a>
                </div>
               {{-- <div class="btn-group">
                    <span class="btn btn-primary" id="repairPoint" href="javascript:void(0)"
                          style="width: 130px;">定位点修复</span>
                </div>--}}
                <div class="hr-line-dashed"></div>
                <form method="get" action="">
                    <div class="col-sm-3" style="padding-left: 0">
                        <div class="input-group search_text">
                            <input type="text" name="name" placeholder="门店名称"
                                   value="{{!empty(request('name'))?request('name'):''}}" class="form-control">
                        </div>
                    </div>
                 {{--   <div class="col-sm-3" style="padding-left: 0">
                        <div class="input-group search_text">
                            <input type="text" name="phone" placeholder="联系方式"
                                   value="{{!empty(request('phone'))?request('phone'):''}}" class="form-control">
                        </div>
                    </div>
--}}
                    <div class="col-sm-3">
                        <select class="form-control" id="store_city" name="city">
                            <option value="">请选择所属城市</option>
                            @foreach($cities as $key=>$city)
                                <option value="{{$key}}" @if(!empty(request('city')) && request('city')==$key) selected @endif>{{$city}}</option>
                            @endforeach
                        </select>
                    </div>
                    <span class="input-group-btn">
                            <button type="submit" class="btn btn-primary">查找</button>
                        </span>
                </form>
            </div>
        </div>
        <div class="hr-line-dashed"></div>
        <table class="table table-striped table-bordered table-hover">
            <thead>
            <tr>
                <th>店铺名称</th>
                <th>店铺联系方式</th>
                <th>所属城市</th>
                <th>置顶</th>
                <th>启用店铺</th>
                <th>操作</th>
            </tr>
            </thead>
            <tbody>
            @if (!empty($data))
                @foreach ($data as $v)
                    <tr>
                        <td>{!! $v->name !!}</td>
                        <td>{!! $v->phone !!}</td>
                        <td>@if(isset($v->cityInfo->name) && $v->cityInfo->name) {!! $v->cityInfo->name !!} @endif</td>

                        <td>{!! $v->top == 1 ? '是' : '否'  !!}</td>
                        <td>{!! $v->is_enable == 1 ? '启用' : '禁用' !!}</td>

                        <td>
                            <a href="{!!route('admin.shop.list.store.curd', ['id' => $v->id])!!}"
                               class="btn btn-xs btn-primary"><i class="fa fa-pencil" data-toggle="tooltip"
                                                                 data-placement="top" title=""
                                                                 data-original-title="编辑"></i></a>

                            <a href="{{route('admin.shop.dashboard',['shop_id'=>$v->id])}}"
                               class="btn btn-xs btn-primary">
                                门店管理
                            </a>

                            <a class="btn btn-xs btn-danger" style="cursor:pointer;"
                               onclick="del_store({!!$v-> id!!});"><i class="fa fa-trash" data-toggle="tooltip"
                                                                      data-placement="top" title=""
                                                                      data-original-title="删除"></i></a>
                        </td>
                    </tr>
                @endforeach
            @endif
            </tbody>
        </table>
        {!! $data->render() !!}
        <div class="pull-right">
        </div>
        <div class="clearfix"></div>
    </div>
</div>

{!! Html::script(env("APP_URL").'/assets/backend/libs/ladda/spin.min.js') !!}
{!! Html::script(env("APP_URL").'/assets/backend/libs/ladda/ladda.min.js') !!}
{!! Html::script(env("APP_URL").'/assets/backend/libs/ladda/ladda.jquery.min.js') !!}
<script>

    $('#store_city').select2({
	    placeholder: '请选择所属城市',
	    allowClear: true
    });

    function del_store(id) {
	    swal({
		    title: "确定删除该门店么？",
		    text: "",
		    type: "warning",
		    showCancelButton: true,
		    confirmButtonColor: "#DD6B55",
		    confirmButtonText: "删除",
		    cancelButtonText: "取消",
		    closeOnConfirm: false,
	    }, function () {
		    $.ajax({
			    type: 'POST',
			    url: "{!!route('store.ajax.del')!!}",
			    data: {'id': id, 'type': 'list'},
			    dataType: 'json',
			    headers: {
				    'X-CSRF-TOKEN': $('meta[name="_token"]').attr('content')
			    },
			    success: function (data) {
				    swal("删除成功", '', "success");
				    location.reload();
			    }
		    });
	    });
    }

    $('#repairPoint').on('click', function () {
	    $.ajax({
		    type: 'GET',
		    url: '{!! route('admin.shop.store.point') !!}',
		    dataType: 'json',
		    beforeSend: function () {
			    $('#repairPoint').ladda().ladda('start');
		    },
		    success: function (res) {
			    $('#repairPoint').ladda().ladda('stop');
			    $('.ladda-progress').remove();
			    $('.ladda-spinner').remove();
			    if (200 == res.code) {
				    swal("修复成功", res.message, "success");
			    }
		    }
	    });
    });

</script>